
package org.apache.solr.update;

import org.apache.solr.request.SolrQueryRequest;

/** An index update command encapsulated in an object (Command pattern)
 */
public abstract class UpdateCommand implements Cloneable {

    public static int BUFFERING         = 0x00000001; // update command is being buffered.
    public static int REPLAY            = 0x00000002; // update command is from replaying a log.
    public static int PEER_SYNC         = 0x00000004; // update command is a missing update being provided by a peer.
    public static int IGNORE_AUTOCOMMIT = 0x00000008; // this update should not count toward triggering of autocommits.
    public static int CLEAR_CACHES      = 0x00000010; // clear caches associated with the update log.  used when applying reordered DBQ updates when doing an add.

    protected SolrQueryRequest req;
    protected long version;
    protected int flags;

    public UpdateCommand(SolrQueryRequest req) {
        this.req = req;
    }

    public abstract String name();

    @Override
    public String toString() {
        return name() + "{flags=" + flags + ",_version_=" + version;
    }

    public long getVersion() {
        return version;
    }

    public void setVersion(long version) {
        this.version = version;
    }

    public void setFlags(int flags) {
        this.flags = flags;
    }

    public int getFlags() {
        return flags;
    }

    public SolrQueryRequest getReq() {
        return req;
    }

    public void setReq(SolrQueryRequest req) {
        this.req = req;
    }

    @Override
    public UpdateCommand clone() {

        try {
            return (UpdateCommand) super.clone();
        }
        catch (CloneNotSupportedException e) {
            return null;
        }
    }
}
